import java.io.Serializable;

//@author A0099409N
public class Task implements Comparable<Task>, Serializable{
	private int _index;
	private String _description;
	private TimeSpan _timeSpan;
	private Reminder _reminderObject;
	private boolean _isUrgent, _isDone, _isJustEdited;

	public Task(String description, TimeSpan timeSpan, 
			boolean urgent, Reminder reminder){
		this._description = description;

		this._timeSpan = new TimeSpan(timeSpan.getStart(), timeSpan.getEnd());

		this._isUrgent = urgent;
		if (reminder != null) {
			this._reminderObject = new Reminder(reminder.getReminderStatus(),reminder.getReminderTime());
		}
		this._isDone = false;
	}

	@Override
	public String toString() {
		String s;
		if (_reminderObject.getReminderTime() == null) {
			s = "Description: " + _description + "\n" 
					+ _timeSpan.toString() + "\n" 
					+ printUrgentStatus() + "\n" 
					+ _reminderObject.printReminderStatus();

		} else {
			s = "Description: " + _description + "\n" + 
					_timeSpan.toString() + "\n" + 
					printUrgentStatus() + "\n" + 
					_reminderObject.printReminderStatus() + " " + 
					TimeParser.printDate(_reminderObject.getReminderTime());
		}
		return s;
	}

	@Override
	public int compareTo(Task j) {
		if (this._isUrgent && j.getUrgent()){
			return this.getTimeSpan().compareTo(
					j.getTimeSpan());
		} else if (this._isUrgent){
			return -1;
		} else if (j.getUrgent()){
			return 1;
		}
		return this.getTimeSpan().compareTo(
				j.getTimeSpan());
	}

	public String getDescription(){
		return _description;
	}

	public void setDescription(String description){
		this._description = description;
	}

	public TimeSpan getTimeSpan(){
		return _timeSpan;
	}

	public void setTimeSpan(TimeSpan timeSpan){
		this._timeSpan = timeSpan;
	}

	public String printUrgentStatus (){
		String status;
		if (_isUrgent){
			status  = "Urgent: On";
		}
		else{
			status = "Urgent: Off";
		}
		return status;
	}

	public void setBoolean (boolean status, String function){
		if (function.equals("urgent")){
			setUrgent(status);
		}
		if (function.equals("reminder")){
			_reminderObject.setReminderStatus(status);
		}
	}

	public void setUrgent(boolean isUrgent){
		this._isUrgent = isUrgent;
	}

	public String printDoneStatus(){
		String status;
		if (_isDone){
			status  = "The item is done";
		}
		else{
			status = "The item is undone";
		}
		return status;
	}

	public Reminder getReminder(){
		return _reminderObject;
	}

	public void setReminder(Reminder reminderObject){
		this._reminderObject = reminderObject;
	}

	public void setDone(boolean isDone){
		this._isDone = isDone;
	}

	public void setIndex(int index) {
		_index = index;
	}

	public int getIndex() {
		return _index;
	}

	public boolean getUrgent(){
		return _isUrgent;
	}

	public boolean isJustEdited() {
		return _isJustEdited;
	}

	public void setJustEdited(boolean isJustEdited) {
		this._isJustEdited = isJustEdited;
	}
}